﻿<div style="width:600px;margin:0 auto;padding-top:20px;">
    <form class="layui-form" action="">
    	<div class="layui-form-item">
            <label class="layui-form-label">菜单名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" win-verify="required" placeholder="请输入菜单名称" autocomplete="off" class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">URL</label>
            <div class="layui-input-block">
                <input type="text" name="url" win-verify="required" placeholder="请输入URL" autocomplete="off" class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">窗口类型</label>
            <div class="layui-input-block winui-radio">
                <input type="radio" name="openType" value="1" title="HTML层" checked/>
                <input type="radio" name="openType" value="2" title="Iframe" />
                <input type="radio" name="openType" value="3" title="标签页" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">窗口标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" win-verify="required" placeholder="请输入窗口标题" autocomplete="off" class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">图标路径</label>
            <div class="layui-input-block">
                <input type="text" name="icon" win-verify="required" placeholder="请输图标路径" autocomplete="off" class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">菜单类型</label>
            <div class="layui-input-block winui-radio">
                <input type="radio" name="menuType" value="1" title="桌面图标" checked/>
                <input type="radio" name="menuType" value="2" title="开始菜单" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input type="text" name="order" win-verify="required" placeholder="请输排序值，由小到大" autocomplete="off" class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="winui-btn" lay-submit lay-filter="formAddMenu">确定</button>
                <button class="winui-btn" onclick="winui.window.close('addMenu'); return false;">取消</button>
            </div>
        </div>
    </form>
</div>
<script>
    layui.use(['form','layer'], function (form) {
        var $ = layui.$, msg = winui.window.msg;
		form.render();
		form.on('submit(formAddMenu)', function(data) {
			//表单验证
			if (winui.verifyForm(data.elem)) {
				layui.$.ajax({
					type : 'post',
					url : '/menus/add',
					contentType : 'application/json;charset=utf-8',
					data : JSON.stringify(data.field),
					dataType : 'json',
					success : function(json) {
						if (json.success) {
							msg('添加成功');
						} else {
							msg(json.message)
						}
						winui.window.close('addMenu');
					},
					error : function(xml) {
						msg('添加失败');
						console.log(xml.responseText);
					}
				});
			}
			return false;
		});
	});
</script>